# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=mscgen
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.20
pkgrel=2
pkgdesc="Message Sequence Chart Generator (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://www.mcternan.me.uk/mscgen/'
license=('GPL')
depends=("${MINGW_PACKAGE_PREFIX}-libgd"
         "${MINGW_PACKAGE_PREFIX}-freetype")
makedepends=("flex" "bison" "${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://fossies.org/linux/privat/${_realname}-src-${pkgver}.tar.gz"
        "0.20-escape.patch"
        "0.20-language.patch"
        "0.20-uninitialized-ymax.patch"
        "0.20-mingw-fix.patch")
sha256sums=('3c3481ae0599e1c2d30b7ed54ab45249127533ab2f20e768a0ae58d8551ddc23'
            '7cdae5bfb7f218405ffdeac4c8b0874da4c60dca89da8702289614d5ecd540ef'
            '62216cf5e6d36c9787eeadbf51817481a41933dbcda151f630a162f7e45b780d'
            '1f81fcbb6e644003c84168f7f78de751edfc6572c71591eea4e80807c643c096'
            '488b79fea3021168ed0a80f8d48f9ba91e628efb63afc12eaeead6945f6ad036')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0.20-escape.patch
  patch -p1 -i ${srcdir}/0.20-language.patch
  patch -p1 -i ${srcdir}/0.20-uninitialized-ymax.patch

  # getenv_s is declared differently in stdlib_s.h (error: conflicting types for 'getenv_s')
  # rename it to avoid compiling error
  patch -p1 -i ${srcdir}/0.20-mingw-fix.patch

  cd ${srcdir}
  [[ -d ${srcdir}/build-${MSYSTEM} ]] && rm -rf ${srcdir}/build-${MSYSTEM}
  cp -rf ${_realname}-${pkgver} build-${MSYSTEM}
}

build() {
  cd "${srcdir}/build-${MSYSTEM}"
  ../${_realname}-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --with-freetype

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
}
